#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
int arr[N];
LL cnt[N];
int n;
int main()
{
	int t;
	scanf_s("%d", &t);
	while (t--) {
		scanf_s("%d", &n);
		memset(arr, 0, sizeof(arr));
		memset(cnt, 0, sizeof(cnt));
		for (int i = 1; i <= n; i++) {
			scanf_s("%d", &arr[i]);
			if (arr[i] < i) {
				cnt[arr[i]]++;
			}
		}
		LL ans = 0;
		for (int i = n; i >= 1; i--) {
			cnt[i] += cnt[i + 1];
		}
		for (int i = 1; i <= n; i++) {
			if (arr[i] < i) {
				ans += cnt[i + 1];
			}
		}
		/*for (int i = 1; i < n; i++) {
			for (int j = i + 1; j <= n; j++) {
				if (arr[j] > i && j > arr[j] && i > arr[i]) {
					ans++;
				}
			}
		}*/
		cout << ans << endl;
	}
	return 0;
}